[% setvar title Standard support for opening i/o handles on scalars and arrays-of-scalars %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Standard support for opening i/o handles on scalars and arrays-of-scalars</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Eryq (Erik Dorfman) &lt;<a href='mailto:eryq@zeegee.com'>eryq@zeegee.com</a>&gt;
  Date: 23 Aug 2000
  Last Modified: 24 Sep 2000
  Mailing List: <a href='mailto:perl6-language-io@perl.org'>perl6-language-io@perl.org</a>
  Number: 186
  Version: 3
  Status: Frozen</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>Support the ability to open an i/o handle on a scalar, and also on an
array-of-scalars.  Implement this in C (for speed), and provide it
in a &quot;standard&quot; extension module (for universal availability).</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>It's extremely useful to be able to open an i/o handle on a
common in-core data structure, such as a scalar or an array-of-lines.
Such a capability breaks down the artificial boundary between core-based
and disk-based data processing, allowing a developer to...</p>
<ul>
<li><a name='Use memory to hold small &quot;temporary files&quot; (fast, secure, portable),'></a>Use memory to hold small &quot;temporary files&quot; (fast, secure, portable),</li>
<li><a name='Reuse filehandle-centric code in non-file-based domains.'></a>Reuse filehandle-centric code in non-file-based domains.</li>
</ul>
<p>The CPAN modules IO::Scalar, IO::ScalarArray, and IO::Lines
currently provide some of this functionality, but their pure-Perl
implementation (chosen for portability) is not as fast or
memory-efficient
as a native implementation could be.  Additionally, since they are not
part of the standard Perl distribution, many developers are either
unaware of their existence or unwilling to obtain and install them.</p>
<p>This RFC proposes that support for &quot;in-core i/o&quot; be folded
into the Perl distribution as a standard extension module, making
use of native C code for speed.</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>As described above.
The following i/o handle classes are proposed as minimally necessary;
they are taken from existing Perl5 CPAN modules with the same names:</p>
<ul>
<li><a name='IO::Scalar'></a>IO::Scalar</li>
<p>An i/o handle which can be opened on a scalar (string) variable.
We simply treat the bytes of the scalar as a &quot;virtual file&quot;.</p>
<li><a name='IO::ScalarArray'></a>IO::ScalarArray</li>
<p>An i/o handle which can be opened on an array of scalar (string)
variables.  Here, the &quot;virtual file&quot; is defined as the concatenation
of the scalars in the array.  One very common way to obtain such a
data structure is to slurp a file into an array.</p>
</ul>
<p>If Perl6 follows Java's example of distinguishing &quot;bytes&quot; from
&quot;characters&quot;, then it should be understood that the proposed i/o handles
manipulate <i>bytes</i>, not characters.  That is, the Java equivalents
are classes like <code>java.io.ByteArrayInputStream</code>.</p>
<p>Character-based i/o should be handled by some additional conversion
mechanism which is wrapped around byte-based i/o; this mechanism
should be applicable to <i>any</i> i/o stream.  A look at the Java
implementation of byte-oriented &quot;input/output streams&quot; versus
character-oriented &quot;readers and writers&quot; is worthwhile for this.</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>IO::Scalar (CPAN)</p>
<p>IO::ScalarArray (CPAN)</p>
</div>
